<?php

namespace app\admin\controller;

use app\admin\service\WxAppService;
use app\common\util\ErrorCode;

class WxAppController extends CommonController
{
    public function getConfigInfo($_type){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        switch ($_type){
            case "setting": // 小程序设置
                $method = "getSetting";
                break;
            case "wxAppTitle": // 获取小程序标题
                $method = "getWxAppTitle";
                break;
            case "slogan": // 获取宣传语
                $method = "getSlogan";
                break;
//            case "debugSetting": // 获取设置信息
//                $method = "getDebugSetting";
//                break;
            default:
                return $this->returnData = ErrorCode::$errorCode["fail"];
                break;
        }
        $service = $this->app->invokeClass(WxAppService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->{$method}();
        return $this->return_result($this->returnData);
    }

    public function getSaveConfig($_type){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        switch ($_type){
            case "setting": // 保存小程序设置
                $method = "getSaveSetting";
                break;
            case "wxAppTitle": // 更新小程序标题
                $method = "updateWxAppTitle";
                break;
            case "slogan": // 更新宣传语
                $method = "updateSlogan";
                break;
//            case "debugSetting": // 更新设置信息
//                $method = "updateDebugSetting";
//                break;
            default:
                return $this->returnData = ErrorCode::$errorCode["fail"];
                break;
        }
        $service = $this->app->invokeClass(WxAppService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->{$method}();
        return $this->return_result($this->returnData);
    }
}
